if(NOT LOTTIETURBO_ROOT_PATH)
    message(FATAL_ERROR "LOTTIETURBO_ROOT_PATH must be setted up at first.")
endif()

set(LOTTIETURBO_SEARCH_PATH ${LOTTIETURBO_ROOT_PATH})
set(CMAKE_CXX_STANDARD 17)
# find base path
find_path(LOTTIETURBO_PATH
    NAMES include/lottie_c.h
    PATHS ${LOTTIETURBO_SEARCH_PATH}
    CMAKE_FIND_ROOT_PATH_BOTH
    )

# find includes
if(NOT LOTTIETURBO_INCLUDE_DIRS)
    find_path(LOTTIETURBO_INCLUDE_DIR
        NAMES lottie_c.h
        PATHS ${LOTTIETURBO_PATH}
        PATH_SUFFIXES include
        CMAKE_FIND_ROOT_PATH_BOTH
    )

    set(LOTTIETURBO_INCLUDE_DIRS
        ${LOTTIETURBO_INCLUDE_DIR})
endif()

# find link directories
if(NOT LOTTIETURBO_LINK_DIRS)
    find_path(LOTTIETURBO_TMP_LINK_DIRS
        NAMES liblottie-turbo.so
        PATHS "${LOTTIETURBO_PATH}"
        PATH_SUFFIXES "libs/${CMAKE_OHOS_ARCH_ABI}"
        CMAKE_FIND_ROOT_PATH_BOTH
    )

    set(LOTTIETURBO_LINK_DIRS
        ${LOTTIETURBO_TMP_LINK_DIRS})

endif()

# find librarys
if(NOT LOTTIETURBO_LIBRARIS)
    find_library(LOTTIETURBO_LIBRARY
        NAMES lottie-turbo
        PATHS "${LOTTIETURBO_PATH}"
        PATH_SUFFIXES "libs/${CMAKE_OHOS_ARCH_ABI}"
        CMAKE_FIND_ROOT_PATH_BOTH
    )

    set(LOTTIETURBO_LIBRARIS
        lottie-turbo
		)

endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LOTTIETURBO DEFAULT_MSG
    LOTTIETURBO_INCLUDE_DIRS
    LOTTIETURBO_LIBRARIS
)

if(LOTTIETURBO_FOUND AND NOT TARGET LOTTIETURBO::lottie-turbo)
    # 创建接口lib
    add_library(LOTTIETURBO::lottie-turbo INTERFACE IMPORTED)

    # 设置target 头文件依赖
    target_include_directories(LOTTIETURBO::lottie-turbo INTERFACE ${LOTTIETURBO_INCLUDE_DIRS})

    # 设置target link依赖路径
    target_link_directories(LOTTIETURBO::lottie-turbo INTERFACE ${LOTTIETURBO_LINK_DIRS})

    # 设置target lib依赖
    target_link_libraries(LOTTIETURBO::lottie-turbo INTERFACE ${LOTTIETURBO_LIBRARIS})

    # 设置target 编译宏
    target_compile_definitions(LOTTIETURBO::lottie-turbo INTERFACE ${LOTTIETURBO_DEFINITIONS})

    # 安全编译选项 NO Rpath 规则
    set(CMAKE_SKIP_RPATH TRUE)
endif()
